#include "SDL2/SDL.h"


//在播放框里面显示画框
int main() {

    SDL_Init(SDL_INIT_VIDEO);

    SDL_Window *window = SDL_CreateWindow("SDLDemo", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
    if (window == NULL) {
        SDL_Log("SDL_CreateWindow failed:%s\n", SDL_GetError());
        return -1;
    }

    SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (renderer == NULL) {
        SDL_Log("SDL_CreateRenderer failed: %s\n", SDL_GetError());
        goto end;
    }

    while (1) {

        SDL_SetRenderDrawColor(renderer, 0, 0, 0,255);
        SDL_RenderClear(renderer);
        SDL_Rect rect;
        rect.x = rand() % 640;
        rect.y = rand() % 480;
        rect.w = 20;
        rect.h = 20;
        SDL_SetRenderDrawColor(renderer, 255, 0, 0,255);
        SDL_RenderDrawRect(renderer, &rect);
        SDL_RenderFillRect(renderer, &rect );//填充框里面的颜色

        SDL_RenderPresent(renderer);

        SDL_Event event;
//        SDL_WaitEvent(&event);
        SDL_PollEvent(&event);
        if (event.type == SDL_Quit) {
            break;
        }
        SDL_Log("event.type: %d\n", event.type);
    }

    end:
//    SDL_Delay(5 * 1000);
    SDL_DestroyWindow(window);
    SDL_Quit();


    return 0;
}